package com.zimin.cloud.web.controller.wiki;

import com.zimin.cloud.mine.pojo.wiki.business.CategoryBO;
import com.zimin.cloud.mine.pojo.wiki.business.EbookBO;
import com.zimin.cloud.wiki.api.ICategoryFeign;
import com.zimin.shared.annotation.RedisLock;
import com.zimin.shared.pojo.Result;
import com.zimin.cloud.wiki.api.IEbookFeign;
import com.zimin.shared.annotation.Idempotence;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

/**
 * @author zimin
 * @since 2021/11/2 4:52 下午
 */
@RestController
@RequestMapping("/web/wiki/ebook")
@Slf4j
public class WebWikiEbookController {

    @Autowired
    private IEbookFeign ebookFeign;

    @GetMapping
    public Mono<Result> wikiEbook(EbookBO ebookBO) {
        Result result = ebookFeign.ebookList(ebookBO);
        return Mono.just(result);
    }

//    @GetMapping("/ebooksByCategoryId")
//    public Mono<Result> getEbooksByCategoryId(EbookBO ebookBO) {
//        Result result = ebookFeign.ebookList(ebookBO);
//        return Mono.just(result);
//    }


    @PostMapping
    @RedisLock
    public Mono<Result> saveEbook(@RequestBody EbookBO ebookBO) {
        Result result = ebookFeign.saveEbook(ebookBO);
        return Mono.just(result);
    }

    @PutMapping
    @RedisLock
    public Mono<Result> updateEbook(@RequestBody EbookBO ebookBO) {
        Result result = ebookFeign.updateEbook(ebookBO);
        return Mono.just(result);
    }

    @DeleteMapping("/{id}")
    public Mono<Result> removeById(@PathVariable(name = "id") String id) {
        Result result = ebookFeign.removeEbookById(id);
        return Mono.just(result);
    }


}
